﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Speech.Synthesis;
using DTO;
using BUS;

namespace Support_Study_Vocabulary
{
    public partial class CtrlTestVocabulary : UserControl
    {
        #region Attributes
        private VOCABULARY _vocabulary;
        private bool _result;
        private string _wordWrote;
        private string _meanEngWrote;
        private string _meanViWrote;        
        public SpeechSynthesizer _speaker;
        public int _indexOnListVcWrote;
        public int typeReview;
        #endregion

        #region Properties
        public bool Result
        {
            get { return _result; }
            set { _result = value; }
        }

        public VOCABULARY Vocabulary
        {
            get { return _vocabulary; }
            set { _vocabulary = value; }
        }

        public string WordWrote
        {
            get { return _wordWrote; }
            set { _wordWrote = value; }
        }

        public string MeanEngWrote
        {
            get { return _meanEngWrote; }
            set { _meanEngWrote = value; }
        }

        public string MeanViWrote
        {
            get { return _meanViWrote; }
            set { _meanViWrote = value; }
        }
        #endregion

        public CtrlTestVocabulary()
        {
            InitializeComponent();
            _result = false;
            typeReview = -1;
        }

        private bool _txtMeanViResized = false;
        public void ShowResult()
        {
            if (typeReview == 1 && !_txtMeanViResized)
            {
                this.txtMeanVi.Size = new Size(this.txtMeanVi.Size.Width - 29, this.txtMeanVi.Size.Height);
                _txtMeanViResized = true;
            }

            this.pbResult.Visible = true;
            this.labResult.Visible = true;
            if (_result)
            {
                this.pbResult.Image = global::Support_Study_Vocabulary.Properties.Resources.True;
                this.labResult.ForeColor = Color.Green;
                this.labSTT.ForeColor = Color.Green;
            }
            else
            {
                this.pbResult.Image = global::Support_Study_Vocabulary.Properties.Resources.False;
                this.labResult.ForeColor = Color.Red;
                this.labSTT.ForeColor = Color.Red;
            }
        }

        public void LoadData()
        {            
            this.txtType.Text = _vocabulary.Type;
            this.txtPho.Text = _vocabulary.Phoneticize;
            string strResult = "Result: ";
            strResult += _vocabulary.Word + " (" + _vocabulary.Type + ") = " + _vocabulary.MeanVi;
            if (_vocabulary.MeanEng != "")
                strResult += " = " + _vocabulary.MeanEng;
            this.labResult.Text = strResult;
            if (typeReview == 1)
            {
                this.txtMeanVi.Text = _vocabulary.MeanVi;
            }
        }

        public void LoadDataWrote(string wordWrote, string meanEngWrote, string meanViWrote)
        {
            this.txtWord.Text = wordWrote;
            this.txtMeanEng.Text = meanEngWrote;
            this.txtMeanVi.Text = meanViWrote;
        }

        private void CtrlTestVocabulary_Load(object sender, EventArgs e)
        {
            if (typeReview == 1)
            {
                this.txtMeanVi.ReadOnly = true;
                this.btnRead.Visible = false;
                this.txtMeanVi.Size = new Size(this.txtMeanVi.Size.Width + 29, this.txtMeanVi.Size.Height);
            }
        }

        private void btnRead_Click(object sender, EventArgs e)
        {
            _speaker.Speak(_vocabulary.Word);
        }

        private void txtWord_TextChanged(object sender, EventArgs e)
        {
            _wordWrote = this.txtWord.Text;
        }

        private void txtMeanEng_TextChanged(object sender, EventArgs e)
        {
            _meanEngWrote = this.txtMeanEng.Text;
        }

        private void txtMeanVi_TextChanged(object sender, EventArgs e)
        {
            _meanViWrote = this.txtMeanVi.Text;
        }
    }
}
